package com.wangcang.widgetlibrary.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.textinput.TextInputLayout;

public class TextInputActivity extends AppCompatActivity {

	private TextInputLayout mTextInputLayout;
	private EditText mEditText;
	private TextInputLayout mTIL;
	private EditText mEtLine;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_text_input);
		mTextInputLayout = (TextInputLayout) findViewById(R.id.text_input_layout);
		mEditText = (EditText) findViewById(R.id.et);
		mEditText.addTextChangedListener(new TextWatcher() {
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count, int after) {

			}

			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				if (s.length() > 11) {
					mTextInputLayout.setStateWrong("收货人电话必须为11位");
				} else {
					mTextInputLayout.setStateNormal();
				}
			}

			@Override
			public void afterTextChanged(Editable s) {

			}
		});
		mTIL = (TextInputLayout) findViewById(R.id.til);
		mEtLine = (EditText) findViewById(R.id.et_line);
		mTIL.postDelayed(new Runnable() {
			@Override
			public void run() {
				mEtLine.setText("啊啊啊啊啊啊");
				mTIL.updateLabelState();
			}
		}, 10000);
//		mTextInputLayout.setEnabled(false);
	}
}
